package com.hspedu.newData.dmsxl.堆;

import java.util.PriorityQueue;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-06 
 * @Version: 1.0
 */

public class LC1046最后一块石头的重量 {

    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> queue = new PriorityQueue<>((a,b)->b-a);
        for (int stone : stones) {
            queue.offer(stone);
        }

        while (queue.size() > 1){
            int a = queue.poll();
            int b = queue.poll();
            if (a > b){
                queue.offer(a-b);
            }
        }
        return queue.isEmpty() ? 0 : queue.poll();
    }
}
